package cn.ejiakanghu.logistics.service.impl;

import cn.com.ejiakanghu.core.exceptions.BizException;
import cn.ejiakanghu.logistics.service.DeployGoodsService;
import cn.hutool.core.util.StrUtil;
import org.linlinjava.litemall.db.dao.AgedmallLgBaseInfoMapper;
import org.linlinjava.litemall.db.dao.AgedmallLgMissionMapper;
import org.linlinjava.litemall.db.domain.AgedmallLgBaseInfo;
import org.linlinjava.litemall.db.domain.AgedmallLgBusiRecord;
import org.linlinjava.litemall.db.domain.AgedmallLgMission;
import org.linlinjava.litemall.db.util.BaseInfoLogisticsStatusErrorMessageEnum;
import org.linlinjava.litemall.db.util.LgBaseInfoStatConstant;
import org.linlinjava.litemall.db.util.LgMissionIsOverEum;
import org.linlinjava.litemall.db.util.LogisticsMissionTypeEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：sujp
 * @date ：Created in 2021/11/5 15:18
 * @description：配货相关操作
 * @modified By：
 * @version: 1.0
 */
@Service
public class DeployGoodsServiceImpl extends LogisticBusiBaseServiceImpl implements DeployGoodsService {

    @Resource
    private LogisticsBaseServiceAbstractImpl logisticsBaseServiceAbstractImpl;
    @Resource
    private AgedmallLgMissionMapper agedmallLgMissionMapper;
    @Resource
    private AgedmallLgBaseInfoMapper agedmallLgBaseInfoMapper;

    /**
     * 创建开始配货任务
     *
     * @param orderCode  agedmall_lg_baseInfo 用户小程序下单单号 (批量插入传)
     * @param baseInfoId agedmall_lg_baseInfo 物流信息id   (单个插入传)
     */
    @Override
    public List<Integer> createStartDeployMiss(String orderCode, Integer baseInfoId) {
        List<Integer> missionIds = new ArrayList<>();
        int type = LogisticsMissionTypeEnum.ALLOT.getCode();
        //配货
        if (orderCode != null) {
            //批量的插入
            missionIds = logisticsBaseServiceAbstractImpl.insertIntoMissonByOrderCode(orderCode, type);
        } else if (baseInfoId != null) {
            //单个的插入
            missionIds = logisticsBaseServiceAbstractImpl.insertIntoOneMission(baseInfoId, type);
        }
        return missionIds;
    }


    /**
     * 配货中
     *
     * @param manId
     * @param missionId
     * @param messageType takeOrder类型
     * @param receiveType
     * @param execType
     */
    @Override
    public void replacementAndDistribution(Integer manId, Integer missionId, Integer messageType, Integer receiveType, Integer execType) {
        logisticsBaseServiceAbstractImpl.logisticsEventInProgress(manId, missionId, messageType, receiveType, execType);
    }

    /**
     * 配货完成
     *
     * @param missionId
     * @param imgs
     */
    @Override
    public void createCompleted(Integer missionId, List<String> imgs) {
        logisticsBaseServiceAbstractImpl.pickingCompleteOperation(missionId, imgs, LgBaseInfoStatConstant.CHANGE_ALLOTING, LgBaseInfoStatConstant.CHANGE_ALLOT_COMPLETE, BaseInfoLogisticsStatusErrorMessageEnum.NOT_IN_STOCKING_STATE.getMessage());
    }
}

